package com.yanqu.road.entity.activity.apprentice.data;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.activity.apprentice.ApprenticeTalentData;
import com.yanqu.road.entity.enums.eOccupationType;

import java.util.List;
import java.util.Random;

public class ApprenticeUserExamData {

    @FieldTypeAnnotation(desc = "士-目标天资")
    private long targetTalent1;

    @FieldTypeAnnotation(desc = "农-目标天资")
    private long targetTalent2;

    @FieldTypeAnnotation(desc = "工-目标天资")
    private long targetTalent3;

    @FieldTypeAnnotation(desc = "商-目标天资")
    private long targetTalent4;

    @FieldTypeAnnotation(desc = "侠-目标天资")
    private long targetTalent5;

    @FieldTypeAnnotation(desc = "士-完成天资")
    private long talent1 = 0;

    @FieldTypeAnnotation(desc = "农-完成天资")
    private long talent2 = 0;

    @FieldTypeAnnotation(desc = "工-完成天资")
    private long talent3 = 0;

    @FieldTypeAnnotation(desc = "商-完成天资")
    private long talent4 = 0;

    @FieldTypeAnnotation(desc = "侠-完成天资")
    private long talent5 = 0;

    @FieldTypeAnnotation(desc = "level配置ID")
    private int levelConfigId;

    @FieldTypeAnnotation(desc = "第几次小考")
    private int examIndex;

    @FieldTypeAnnotation(desc = "天资奖励")
    private List<Integer> talentReward;

    @FieldTypeAnnotation(desc = "创建时间")
    private long createTime;

    public long getTargetTalent1() {
        return targetTalent1;
    }

    public void setTargetTalent1(long targetTalent1) {
        this.targetTalent1 = targetTalent1;
    }

    public long getTargetTalent2() {
        return targetTalent2;
    }

    public void setTargetTalent2(long targetTalent2) {
        this.targetTalent2 = targetTalent2;
    }

    public long getTargetTalent3() {
        return targetTalent3;
    }

    public void setTargetTalent3(long targetTalent3) {
        this.targetTalent3 = targetTalent3;
    }

    public long getTargetTalent4() {
        return targetTalent4;
    }

    public void setTargetTalent4(long targetTalent4) {
        this.targetTalent4 = targetTalent4;
    }

    public long getTargetTalent5() {
        return targetTalent5;
    }

    public void setTargetTalent5(long targetTalent5) {
        this.targetTalent5 = targetTalent5;
    }

    public long getTalent1() {
        return talent1;
    }

    public void setTalent1(long talent1) {
        this.talent1 = talent1;
    }

    public long getTalent2() {
        return talent2;
    }

    public void setTalent2(long talent2) {
        this.talent2 = talent2;
    }

    public long getTalent3() {
        return talent3;
    }

    public void setTalent3(long talent3) {
        this.talent3 = talent3;
    }

    public long getTalent4() {
        return talent4;
    }

    public void setTalent4(long talent4) {
        this.talent4 = talent4;
    }

    public long getTalent5() {
        return talent5;
    }

    public void setTalent5(long talent5) {
        this.talent5 = talent5;
    }

    public int getLevelConfigId() {
        return levelConfigId;
    }

    public void setLevelConfigId(int levelConfigId) {
        this.levelConfigId = levelConfigId;
    }

    public int getExamIndex() {
        return examIndex;
    }

    public void setExamIndex(int examIndex) {
        this.examIndex = examIndex;
    }

    public List<Integer> getTalentReward() {
        return talentReward;
    }

    public void setTalentReward(List<Integer> talentReward) {
        this.talentReward = talentReward;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    /**
     * 添加天资
     * @param type
     * @param talent
     */
    public synchronized void addTalent(int type, long talent) {
        if (eOccupationType.Scholar.getValue() == type) {
            this.talent1 += talent;
            this.setTalent1(this.talent1);
        } else if (eOccupationType.Farmer.getValue() == type) {
            this.talent2 += talent;
            this.setTalent2(this.talent2);
        } else if (eOccupationType.Craftsman.getValue() == type) {
            this.talent3 += talent;
            this.setTalent3(this.talent3);
        } else if (eOccupationType.Businessman.getValue() == type) {
            this.talent4 += talent;
            this.setTalent4(this.talent4);
        } else if (eOccupationType.Knight.getValue() == type) {
            this.talent5 += talent;
            this.setTalent5(this.talent5);
        }
    }

    /**
     * 添加天资
     * @param type
     * @param talent
     */
    public synchronized void setTargetTalent(int type, long talent) {
        if (eOccupationType.Scholar.getValue() == type) {
            this.setTargetTalent1(talent);
        } else if (eOccupationType.Farmer.getValue() == type) {
            this.setTargetTalent2(talent);
        } else if (eOccupationType.Craftsman.getValue() == type) {
            this.setTargetTalent3(talent);
        } else if (eOccupationType.Businessman.getValue() == type) {
            this.setTargetTalent4(talent);
        } else if (eOccupationType.Knight.getValue() == type) {
            this.setTargetTalent5(talent);
        }
    }

    /**
     * 获取达标数量
     * @return
     */
    public int getSuccessNum() {
        int successNum = 0;
        if (this.talent1 >= this.targetTalent1) {
            successNum++;
        }
        if (this.talent2 >= this.targetTalent2) {
            successNum++;
        }
        if (this.talent3 >= this.targetTalent3) {
            successNum++;
        }
        if (this.talent4 >= this.targetTalent4) {
            successNum++;
        }
        if (this.talent5 >= this.targetTalent5) {
            successNum++;
        }
        long allTalent = this.talent1 + this.talent2 + this.talent3 + this.talent4 + this.talent5;
        long targetTalent = this.targetTalent1 + this.targetTalent2 + this.targetTalent3 + this.targetTalent4 + this.targetTalent5;
        if (allTalent >= targetTalent) {
            successNum++;
        }
        return successNum;
    }
}
